home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / SubCell.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  3.5 KB  |  166 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10. static char RCSId[]="$Id: SubCell.m,v 1.5 1993/05/04 16:22:56 davis Exp $";
  11.  
  12.  
  13. /*  
  14.  *  Based on CustomCell in the NeXT Developer Example ScrollDoodScroll 
  15.  *  by Jayson Adams.
  16.  */
  17.  
  18. #import <appkit/Font.h>
  19. #import <appkit/NXImage.h>
  20. #import <appkit/Text.h>        /* NXTextFontInfo()        */
  21.  
  22. #import <dpsclient/wraps.h>
  23.  
  24. #import "SubCell.h"
  25. #import "SubObject.h"
  26.  
  27.  
  28. #define FIRST_COLUMN_START 4.0
  29. #define TEXT_COLUMN_START 20.0
  30.  
  31.  
  32. @implementation SubCell
  33.  
  34. static id     attachmentImage = nil;
  35. static NXSize    imageSize;
  36.  
  37.  
  38. + initialize
  39. {
  40.     /* Get the "attachment" image -- like the image in NeXTMail */
  41.     if (!attachmentImage) {
  42.     attachmentImage = [NXImage findImageNamed:"Attachment"];
  43.     [attachmentImage getSize:&imageSize];
  44.     }
  45.  
  46.     return self;
  47. }
  48.  
  49.  
  50. - init
  51. {
  52.     [super init];
  53.     [self setStringValue:""];
  54.     return self;
  55. }
  56.  
  57.  
  58. - setFont:fontObj
  59. {
  60.     [super setFont:fontObj];
  61.     /*
  62.      *  Save this info so we don't have to look it up every time we 
  63.      *  draw.  Note:  "support" for a text Cell is a font object.
  64.      */
  65.     NXTextFontInfo(support, &ascender, &descender, &lineHeight);
  66.  
  67.     return self;
  68. }
  69.  
  70.  
  71.  
  72. - drawInside:(const NXRect *)cellFrame inView:controlView
  73. {
  74.     NXPoint    imageOrigin;
  75.     NXRect    rectArray[2];
  76.     
  77.     /*  Set the font according to our drawing status.  */
  78.     if (NXDrawingStatus == NX_DRAWING)
  79.     [[support screenFont] set];
  80.     else
  81.     [support set];
  82.     
  83.  
  84.     /*  Erase the cell.  */
  85.     PSsetgray((cFlags1.state || cFlags1.highlighted) ? NX_WHITE : NX_LTGRAY);
  86.     NXRectFill(cellFrame);
  87.  
  88.     /*  Draw the "attachment" image, if the SubObject wants us to.  */
  89.     if (showAttachment) {
  90.     imageOrigin.x = FIRST_COLUMN_START;
  91.     imageOrigin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame) - 1
  92.                 - (NX_HEIGHT(cellFrame) - imageSize.height) / 2.0;
  93.     [attachmentImage composite:NX_PLUSD toPoint:&imageOrigin];
  94.     }
  95.       
  96.  
  97.     /*  Draw the text.  */
  98.     PSsetgray(NX_BLACK);
  99.     PSmoveto(NX_X(cellFrame) + TEXT_COLUMN_START,
  100.              NX_Y(cellFrame) + lineHeight - descender);
  101.     PSshow(contents);
  102.     
  103.  
  104.     /*  Draw the two dark gray lines above and below the cell.  */
  105.     PSsetgray(NX_DKGRAY);
  106.     if (cFlags1.state || cFlags1.highlighted) {
  107.     /*
  108.      *  Draw 1-pixel-high rectangles instead of lines (this is 
  109.      *  faster than PSmoveto(); PSlineto()).
  110.      */
  111.     NXSetRect(&(rectArray[0]), NX_X(cellFrame), NX_Y(cellFrame),
  112.           NX_WIDTH(cellFrame), 1.0);
  113.     NXSetRect(&(rectArray[1]), NX_X(cellFrame), NX_MAXY(cellFrame) - 1.0,
  114.           NX_WIDTH(cellFrame), 1.0);
  115.  
  116.     /*  
  117.      *  Using NXRectFillList is faster than separate calls to 
  118.      *  NXRectFill.
  119.      */
  120.     NXRectFillList(rectArray, 2);
  121.     }
  122.  
  123.     return self;
  124. }
  125.  
  126.  
  127.  
  128. /*  
  129.  *  This class implements the SubCell category of Cell.  Every cell 
  130.  *  that does so has associated with it an object which stores the 
  131.  *  information that the Cell displays.  When the sub object is set,
  132.  *  we set our instance variables to match it.
  133.  */
  134. - setSubObject:anObject
  135. {
  136.     if (anObject) {
  137.     const char *aString;
  138.  
  139.     subObject = anObject;
  140.     aString = [subObject stringValue];
  141.     [self setStringValue: aString? aString: ""];
  142.     showAttachment = [subObject isAttachment];
  143.  
  144.     return self;
  145.  
  146.     } else
  147.     return nil;
  148. }
  149.  
  150.  
  151. - subObject
  152. {
  153.     return subObject;
  154. }
  155.  
  156.  
  157.  
  158. // Shuts up the compiler about unused RCSId
  159. - (const char *) rcsid
  160. {
  161.     return RCSId;
  162. }
  163.  
  164.  
  165. @end
  166.